using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;

namespace Weight.Base
{
    /// <summary>
    /// 配置文件实体类
    /// </summary>
    [XmlTypeAttribute(AnonymousType = true)]
    [XmlRootAttribute(Namespace = "", IsNullable = false)]
    public class DeviceSetting : BaseSetting
    {
        public DevControl Control;
        public Video VideoSetting;
        public Company CompanyName;

        [XmlArray]
        public List<WTMeter> Meters;

        //控制器设备集合
        [XmlArray]
        public List<ControlDevice> ControlDevices { get; set; }

        [XmlArray]
        public List<ICCard> IC;
        [XmlArray]
        public List<RFIDCard> RFID;
        [XmlArray]
        public List<IDCardM> IDM;
        [XmlArray]
        public List<IDCardN> IDN;

        public Indentity Indentity;
        [XmlArray]
        public List<LED> Leds;

        [XmlArray]
        public List<PlateNumVideo> PlateNumVideos { get; set; }

        /// <summary>
        ///默认配置
        /// </summary>
        public DeviceSetting()
        {
            ///仪表配置
            Meters = new List<WTMeter>();
            ///控制器
            Control = new DevControl();
            ///公司
            CompanyName = new Company();
            ///版本
            XmlVersion = new Version();

            //初始化监控配置
            VideoSetting = new Video();

            //初始化射频卡配置
            IC = new List<ICCard>();
            RFID = new List<RFIDCard>();
            IDM = new List<IDCardM>();
            IDN = new List<IDCardN>();
            Indentity = new Indentity();

            //初始化LED配置
            Leds = new List<LED>();
            ///控制器设备集合
            ControlDevices = new List<ControlDevice>();

            /// 车号识别系统
            PlateNumVideos = new List<PlateNumVideo>();
        }

        /// <summary>
        /// 设置设备的默认配置
        /// </summary>
        public override void setDefaultConfig()
        {
            if(Meters.Count == 0)
            {
                for (int i = 0; i < 2; i++)
                {
                    Meters.Add(new WTMeter() {
                        Port = 0,
                        Budrate = 0,
                        Type = "待配置",
                        StartPoint = 0,
                        SteadyTime =5
                    });
                }
            }
            if (Leds.Count == 0)
            {
                for (int index = 0; index < 2; index++)
                {
                    Leds.Add(new LED()
                    {
                        No= index+1,
                        Ip = "未配置",
                        Port = -1,
                        Baudrate = 0,
                        FontSize = 0,
                        Width = 0,
                        Height = 0,
                        Action = 0
                    });
                }
            }

            if (IC.Count == 0)
            {
                for (int index = 0; index < 2; index++)
                {
                    IC.Add(new ICCard()
                    {
                        No = index+1,
                        Enable = false,
                        Port = -1,
                        Baudrate = 0,
                    });

                }
            }

            if (RFID.Count == 0)
            {
                for (int index = 0; index < 2; index++)
                {
                    RFID.Add(new RFIDCard()
                    {
                        No = index + 1,
                        Enable = false,
                        Port = -1,
                        Baudrate = 0,
                        Power = 20,
                    });

                }
            }

            if (IDM.Count == 0)
            {
                for (int index = 0; index < 2; index++)
                {
                    IDM.Add(new IDCardM()
                    {
                        No = index+1,
                        Enable = false,
                        Port = -1,
                        Baudrate = 0,
                    });

                }
            }

            if (IDN.Count == 0)
            {
                for (int index = 0; index < 2; index++)
                {
                    IDN.Add(new IDCardN()
                    {
                        No = index+1,
                        Enable = false,
                        Port = -1,
                        Baudrate = 0,
                    });
                }
            }

            Indentity = new Indentity();

            if (VideoSetting.Channels.Count == 0)
            {
                for (int index = 0; index < 6; index++)
                {
                    VideoSetting.Channels.Add("0");
                }
            }

            ///控制器设备初始化
            if(ControlDevices.Count == 0)
            {
                for (int i = 0; i < 8; i++)
                {
                    ControlDevices.Add( new ControlDevice() {
                        DevName = "待配置",
                        ControlPort = 0
                    });
                }
            }

            /// 车号识别系统初始化
            if(PlateNumVideos.Count == 0)
            {
                for (int i = 0; i < 2; i++)
                {
                    PlateNumVideos.Add(new PlateNumVideo()
                    {
                        DevType ="待配置",
                        No=i,
                        Ip = "待配置",
                        Port = 0,
                        Account ="待配置",
                        Pwd = "待配置"
                    }) ;
                }
            }
        }
    }


    /// <summary>
    /// 仪表配置
    /// </summary>
    public class WTMeter
    {
        /// <summary>
        /// 串口
        /// </summary>
        [XmlAttribute]
        public int Port { get; set; }

        /// <summary>
        /// 波特率
        /// </summary>
        [XmlAttribute]
        public int Budrate { get; set; }

        /// <summary>
        /// 仪表类型
        /// </summary>
        [XmlAttribute]
        public string  Type { get; set; }

        /// <summary>
        /// 检测起点
        /// </summary>
        [XmlAttribute]
        public double StartPoint { get; set; }

        /// <summary>
        /// 稳定延时
        /// </summary>
        [XmlAttribute]
        public int SteadyTime { get; set; }

        /// <summary>
        /// 计量单位
        /// </summary>
        [XmlAttribute]
        public string Unit { get; set; }

        /// <summary>
        /// 仪表编号
        /// </summary>
        [XmlAttribute]
        public int MeterNum { get; set; }

    }

    /// <summary>
    /// 控制器
    /// </summary>
    public class ControlDevice
    {
        /// <summary>
        /// 设备名称
        /// </summary>
        [XmlText]
        public string DevName { get; set; }

        /// <summary>
        /// 控制器端子
        /// </summary>
        [XmlAttribute]
        public int ControlPort { get; set; }

        /// <summary>
        /// 是否是输入设备
        /// </summary>
        [XmlAttribute]
        public bool IsInput { get; set; }
    }



    /// <summary>
    /// 控制器实体类
    /// </summary>
    public class DevControl
    {
        public DevControl()
        {
            Ip = "待配置";
            Port = 0;
            Enable = false;
        }
        /// <summary>
        /// 网络地址
        /// </summary>
        [XmlAttribute]
        public string Ip { get; set; }

        /// <summary>
        /// 端口
        /// </summary>
        [XmlAttribute]
        public int Port { get; set; }

        /// <summary>
        /// 是否可用
        /// </summary>
        [XmlAttribute]
        public bool Enable { get; set; }
    }


    /// <summary>
    /// IC 卡配置
    /// </summary>
    public class ICCard
    {
        /// <summary>
        /// 设备号
        /// </summary>
        [XmlAttribute]
        public int No;

        /// <summary>
        /// 设备是否开启
        /// </summary>
        [XmlAttribute]
        public bool Enable { get; set; }
        /// <summary>
        /// IC 卡串口
        /// </summary>
        [XmlAttribute]
        public int Port { get; set; }

        /// <summary>
        /// IC卡波特率
        /// </summary>
        [XmlAttribute]
        public int Baudrate { get; set; }
    }

    /// <summary>
    /// RFID（电子标签）
    /// </summary>
    public class RFIDCard
    {
        /// <summary>
        /// 设备号
        /// </summary>
        [XmlAttribute]
        public int No;
        /// <summary>
        /// 设备是否开启
        /// </summary>
        [XmlAttribute]
        public bool Enable { get; set; }
        /// <summary>
        /// RFID 卡串口号
        /// </summary>
        [XmlAttribute]
        public int Port { get; set; }

        /// <summary>
        /// RFID 波特率
        /// </summary>
        [XmlAttribute]
        public int Baudrate { get; set; }

        /// <summary>
        /// RFID 功率
        /// </summary>
        [XmlAttribute]
        public int Power { get; set; }
    }

    /// <summary>
    /// ID卡标签(中距)
    /// </summary>
    public class IDCardM
    {
        /// <summary>
        /// 设备号
        /// </summary>
        [XmlAttribute]
        public int No;
        /// <summary>
        /// 设备是否开启
        /// </summary>
        [XmlAttribute]
        public bool Enable { get; set; }
        /// <summary>
        /// 端口号
        /// </summary>
        [XmlAttribute]
        public int Port { get; set; }

        /// <summary>
        /// 波特率
        /// </summary>
        [XmlAttribute]
        public int Baudrate { get; set; }
    }

    /// <summary>
    /// ID卡标签(近距)
    /// </summary>
    public class IDCardN
    {
        /// <summary>
        /// 设备号
        /// </summary>
        [XmlAttribute]
        public int No;
        /// <summary>
        /// 设备是否开启
        /// </summary>
        [XmlAttribute]
        public bool Enable { get; set; }
        /// <summary>
        /// 端口号
        /// </summary>
        [XmlAttribute]
        public int Port { get; set; }

        /// <summary>
        /// 波特率
        /// </summary>
        [XmlAttribute]
        public int Baudrate { get; set; }
    }

    /// <summary>
    /// 身份证
    /// </summary>
    public class Indentity
    {
        /// <summary>
        /// 设备是否开启
        /// </summary>
        [XmlAttribute]
        public bool Enable { get; set; }
        /// <summary>
        /// 端口号
        /// </summary>
        [XmlAttribute]
        public int Port { get; set; }

        /// <summary>
        /// 波特率
        /// </summary>
        [XmlAttribute]
        public int Baudrate { get; set; }

        /// <summary>
        /// 扩展盒
        /// </summary>
        [XmlAttribute]
        public string ExtBox { get; set; }
    }

    /// <summary>
    /// LED 大屏幕参数配置
    /// </summary>
    public class LED
    {
        /// <summary>
        /// 设备编号
        /// </summary>
        [XmlAttribute]
        public int No { get; set; }

        /// <summary>
        /// 设备是否开启
        /// </summary>
        [XmlAttribute]
        public bool Enable { get; set; }

        [XmlAttribute]
        //IP地址
        public string Ip { get; set; }


        [XmlAttribute]
        /// <summary>
        /// 端口号
        /// </summary>
        public int Port { get; set; }

        [XmlAttribute]
        /// <summary>
        /// 波特率
        /// </summary>
        public int Baudrate { get; set; }

        [XmlAttribute]
        /// <summary>
        /// 宽度
        /// </summary>
        public int Width { get; set; }

        [XmlAttribute]
        /// <summary>
        /// 高度
        /// </summary>
        public int Height { get; set; }

        [XmlAttribute]
        /// <summary>
        /// 字体大小
        /// </summary>
        public int FontSize { get; set; }

        /// <summary>
        /// 特技
        /// </summary>
        [XmlAttribute]
        public int Action { get; set; }

        /// <summary>
        /// LED 类型
        /// </summary>
        [XmlAttribute]
        public string LEDType { get; set; }
    }


    /// <summary>
    /// 监控配置
    /// </summary>
    public class Video
    {
        public Video()
        {
            VideoIp = "192.168.2.0";
            VideoPort = 8000;
            Account = "admin";
            Pwd = "123";
            Type = "海康";
            Memo = "未配置";
            Enable = false;
            CaptureImg = new Capture()
            {
                Enable = false,
                IsWatermark = false,
                X = 30,
                Y = 30,
                Space = 5,
                FontSize = 12
            };
        }
        [XmlAttribute]
        public string VideoIp { get; set; }
        [XmlAttribute]
        public Int16 VideoPort { get; set; }
        [XmlAttribute]
        public string Account { get; set; }
        [XmlAttribute]
        public string Pwd { get; set; }
        [XmlAttribute]
        public string Type { get; set; }
        [XmlAttribute]
        public bool Enable { get; set; }
        [XmlArray]
        public List<string> Channels { get; set; }
        /// <summary>
        /// 配置说明
        /// </summary>
        public string Memo { get; set; }

        public Capture CaptureImg { get; set; }

        /// <summary>
        /// 图片抓拍
        /// </summary>
       public  class Capture
        {
            /// <summary>
            /// 是否抓拍图片
            /// </summary>
            [XmlAttribute]
            public bool Enable { get; set; }

            /// <summary>
            /// 是否添加水印
            /// </summary>
            [XmlAttribute]
            public bool IsWatermark { get; set; }

            /// <summary>
            /// 水印横坐标位置
            /// </summary>
            [XmlAttribute]
            public int X { get; set; }

            /// <summary>
            /// 水印纵坐标位置
            /// </summary>
            [XmlAttribute]
            public int Y { get; set; }

            /// <summary>
            /// 间距
            /// </summary>
            [XmlAttribute]
            public int Space { get; set; }

            /// <summary>
            /// 字体大小
            /// </summary>
            [XmlAttribute]
            public int FontSize { get; set; }
        }
    }

    /// <summary>
    /// 车号识别配置
    /// </summary>
    public class PlateNumVideo
    {
        /// <summary>
        /// 设备型号
        /// </summary>
        [XmlAttribute]
        public string DevType { get; set; }
        /// <summary>
        /// 编号
        /// </summary>
        [XmlAttribute]
        public int No { get; set; }
        /// <summary>
        /// 设备是否可用
        /// </summary>
        [XmlAttribute]
        public bool Enable { get; set; }

        /// <summary>
        /// Ip 地址
        /// </summary>
        [XmlAttribute]
        public string Ip { get; set; }

        /// <summary>
        /// 端口号
        /// </summary>
        [XmlAttribute]
        public int Port { get; set; }

        /// <summary>
        /// 登录账号
        /// </summary>
        [XmlAttribute]
        public string Account { get; set; }

        /// <summary>
        /// 登录密码
        /// </summary>
        [XmlAttribute]
        public string Pwd { get; set; }
    }
}


